<?php

use think\migration\Migrator;

class Init extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('application');
        $table->addColumn('title', 'string', ['limit' => 200])
            ->addColumn('user_id', 'integer',)
            ->addColumn('record_user_id', 'integer')
            ->addColumn('verify_user_id', 'integer', ['null' => true])
            ->addColumn('start_time', 'integer')
            ->addColumn('end_time', 'integer')
            ->addColumn('type', 'integer', ['limit' => 1])
            ->addColumn('machine_list', 'json')
            ->addColumn('goods_list', 'json')
            ->addColumn('attach_list', 'integer', ['null' => true])
            ->addColumn('reject_reason', 'string')
            ->addColumn('status', 'integer', ['limit' => 1, 'comment' => '0=拒绝 1=审核中 2=通过 3=结束'])
            ->addColumn('create_time', 'integer', ['null' => true])
            ->addColumn('update_time', 'integer', ['null' => true])
            ->create();

        $table = $this->table('attach');
        $table->addColumn('key', 'string', ['limit' => 200])
            ->addColumn('user_id', 'integer')
            ->addColumn('name', 'string')
            ->addColumn('mimeType', 'string')
            ->addColumn('path', 'string')
            ->addColumn('create_time', 'integer', ['null' => true])
            ->addColumn('update_time', 'integer', ['null' => true])
            ->create();

        $table = $this->table('category');
        $table->addColumn('name', 'string', ['limit' => 200])
            ->addColumn('description', 'string')
            ->addColumn('create_time', 'integer', ['null' => true])
            ->addColumn('update_time', 'integer', ['null' => true])
            ->create();

        $table = $this->table('inventory');
        $table->addColumn('user_id', 'integer')
            ->addColumn('record_user_id', 'integer')
            ->addColumn('verify_user_id', 'integer', ['null' => true])
            ->addColumn('warehouse_id', 'integer', ['null' => true])
            ->addColumn('type', 'integer', ['limit' => 1])
            ->addColumn('title', 'string', ['limit' => 200])
            ->addColumn('goods_list', 'json')
            ->addColumn('voucher', 'json', ['null' => true])
            ->addColumn('reject_reason', 'string')
            ->addColumn('status', 'integer', ['limit' => 1, 'comment' => '-1=拒绝 1=通过 0=审核中'])
            ->addColumn('create_time', 'integer', ['null' => true])
            ->addColumn('update_time', 'integer', ['null' => true])
            ->create();

        $table = $this->table('loan');
        $table->addColumn('user_id', 'integer')
            ->addColumn('record_user_id', 'integer')
            ->addColumn('verify_user_id', 'integer', ['null' => true])
            ->addColumn('warehouse_id', 'integer', ['null' => true])
            ->addColumn('title', 'string', ['limit' => 200])
            ->addColumn('goods_list', 'json')
            ->addColumn('voucher', 'json', ['null' => true])
            ->addColumn('reject_reason', 'string')
            ->addColumn('status', 'integer', ['limit' => 1, 'comment' => '-1=拒绝 1=通过 0=审核中'])
            ->addColumn('create_time', 'integer', ['null' => true])
            ->addColumn('update_time', 'integer', ['null' => true])
            ->create();

        $table = $this->table('logs');
        $table->addColumn('user_id', 'integer')
            ->addColumn('content', 'text')
            ->addColumn('ip', 'string')
            ->addColumn('level', 'integer', ['limit' => 1])
            ->addColumn('create_time', 'integer', ['null' => true])
            ->addColumn('update_time', 'integer', ['null' => true])
            ->create();

        $table = $this->table('machines');
        $table->addColumn('name', 'string')
            ->addColumn('property_id', 'string', ['limit' => 30, 'comment' => '学校资产编号'])
            ->addColumn('model', 'string')
            ->addColumn('cover', 'string', ['limit' => 200, 'comment' => '缩略图', 'null' => true])
            ->addColumn('last_maintenance_time', 'integer', ['limit' => 11, 'comment' => '上次维护时间', 'null' => true])
            ->addColumn('status', 'integer', ['limit' => 1, 'comment' => '设备状态 0=损坏 1=正常 2=维护', 'default' => 1])
            ->addColumn('create_time', 'integer', ['null' => true])
            ->addColumn('update_time', 'integer', ['null' => true])
            ->create();

        $table = $this->table('materials');
        $table->addColumn('name', 'string', ['limit' => 30])
            ->addColumn('category_id', 'integer', ['limit' => 5, 'default' => 1])
            ->addColumn('warehouse_id', 'integer', ['limit' => 5, 'default' => 1])
            ->addColumn('cover', 'string', ['limit' => 200, 'null' => true])
            ->addColumn('unit', 'string', ['limit' => 20, 'null' => true])
            ->addColumn('specs', 'string', ['limit' => 30, 'null' => true])
            ->addColumn('total', 'integer', ['limit' => 11, 'default' => 0])
            ->addColumn('price', 'decimal', ['default' => 0])
            ->addColumn('material_id', 'string', ['limit' => 30])
            ->addColumn('bar_code', 'string', ['limit' => 30, 'null' => true])
            ->addColumn('notes', 'string', ['limit' => 255, 'null' => true])
            ->addColumn('create_time', 'integer', ['limit' => 11, 'null' => true])
            ->addColumn('update_time', 'integer', ['limit' => 11, 'null' => true])
            ->create();

        $table = $this->table('options');
        $table->addColumn('name', 'string', ['limit' => 30])
            ->addColumn('value', 'text', ['null' => true])
            ->addColumn('group', 'string', ['limit' => 200, 'null' => true])
            ->addColumn('create_time', 'integer', ['limit' => 11, 'null' => true])
            ->addColumn('update_time', 'integer', ['limit' => 11, 'null' => true])
            ->create();

        $table = $this->table('rules');
        $table->addColumn('name', 'string', ['limit' => 15])
            ->addColumn('rule', 'string', ['limit' => 100])
            ->addColumn('status', 'integer', ['limit' => 1, 'default' => -1])
            ->addColumn('create_time', 'integer', ['limit' => 11, 'null' => true])
            ->addColumn('update_time', 'integer', ['limit' => 11, 'null' => true])
            ->create();

        $table = $this->table('user_group');
        $table->addColumn('name', 'string', ['limit' => 15])
            ->addColumn('description', 'string', ['limit' => 100])
            ->addColumn('rules', 'string')
            ->addColumn('status', 'integer', ['limit' => 1, 'default' => -1])
            ->addColumn('create_time', 'integer', ['limit' => 11, 'null' => true])
            ->addColumn('update_time', 'integer', ['limit' => 11, 'null' => true])
            ->create();

        $table = $this->table('user_profile');
        $table->addColumn('user_id', 'integer', ['limit' => 11])
            ->addColumn('name', 'string', ['limit' => 4])
            ->addColumn('avatar', 'string', ['limit' => 200])
            ->addColumn('gender', 'integer', ['limit' => 1, 'comment' => '性别'])
            ->addColumn('department', 'string', ['limit' => 10, 'default' => '会员'])
            ->addColumn('grade', 'string', ['limit' => 10, 'comment' => '年级'])
            ->addColumn('class', 'string', ['limit' => 10, 'comment' => '班级'])
            ->addColumn('phone', 'string', ['limit' => 11, 'comment' => '手机号码'])
            ->addColumn('qq_account', 'string', ['limit' => 10, 'comment' => 'QQ号'])
            ->addColumn('cnc_experience', 'integer', ['limit' => 1, 'comment' => '数控经验'])
            ->addColumn('demand', 'string', ['limit' => 100, 'comment' => '相关需求', 'null' => true])
            ->addColumn('create_time', 'integer', ['limit' => 11, 'null' => true])
            ->addColumn('update_time', 'integer', ['limit' => 11, 'null' => true])
            ->create();

        $table = $this->table('users');
        $table->addColumn('user_group_id', 'integer', ['limit' => 3, 'default' => -1])
            ->addColumn('card', 'string', ['limit' => 18])
            ->addColumn('phone', 'string', ['limit' => 18])
            ->addColumn('student_id', 'string', ['limit' => 18])
            ->addColumn('password', 'string', ['limit' => 60])
            ->addColumn('status', 'integer', ['limit' => 1, 'default' => -1])
            ->addColumn('create_time', 'integer', ['limit' => 11, 'null' => true])
            ->addColumn('update_time', 'integer', ['limit' => 11, 'null' => true])
            ->create();

        $table = $this->table('warehouse');
        $table->addColumn('name', 'string', ['limit' => 200])
            ->addColumn('admin_user_id', 'integer', ['comment' => '管理员'])
            ->addColumn('position', 'string', ['limit' => 50, 'comment' => '所属教室'])
            ->addColumn('last_inventory_time', 'integer', ['comment' => '最后一次盘点时间'])
            ->addColumn('create_time', 'integer', ['null' => true])
            ->addColumn('update_time', 'integer', ['null' => true])
            ->create();
    }
}
